home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 June
/
CHIP Haziran 2001.iso
/
prog
/
haziran
/
19
/
setup.exe
/
data.z
/
windrvr_int_thread.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2001-04-11
|
2KB
|
93 lines
unit WinDrvr_Int_Thread;
interface
uses
Windows,
windrvr;
type
INT_HANDLER_FUNC = procedure(pData : POINTER);
PWD_INTERRUPT = ^WD_INTERRUPT;
INT_THREAD_DATA = record
hThread : HANDLE;
hWD : HANDLE;
func : INT_HANDLER_FUNC;
pData : POINTER;
pInt : PWD_INTERRUPT;
end;
PINT_THREAD_DATA = ^INT_THREAD_DATA;
function InterruptThreadHandler(pData : POINTER) : INTEGER;
function InterruptThreadEnable(phThread : PHANDLE; hWD : HANDLE; pInt : PWD_INTERRUPT; func : INT_HANDLER_FUNC; pData : POINTER) : BOOLEAN;
procedure InterruptThreadDisable(hThread : HANDLE);
implementation
function InterruptThreadHandler(pData : POINTER) : INTEGER;
var
pThread : PINT_THREAD_DATA;
begin
pThread := PINT_THREAD_DATA (pData);
while True do
begin
WD_IntWait(pThread^.hWD, pThread^.pInt^);
if pThread^.pInt^.fStopped = 1
then
Break;
pThread^.func(pThread^.pData);
end;
InterruptThreadHandler := 0;
end;
function InterruptThreadEnable(phThread : PHANDLE; hWD : HANDLE; pInt : PWD_INTERRUPT; func : INT_HANDLER_FUNC; pData : POINTER) : BOOLEAN;
var
pThread : ^INT_THREAD_DATA;
begin
phThread^ := 0;
WD_IntEnable(hWD, pInt^);
{ check if WD_IntEnable failed }
if not (pInt^.fEnableOk = 1)
then
begin
InterruptThreadEnable := False;
Exit;
end;
GetMem(POINTER(pThread), SizeOf(INT_THREAD_DATA));
pThread^.func := func;
pThread^.pData := pData;
pThread^.hWD := hWD;
pThread^.pInt := pInt;
pThread^.hThread := BeginThread (nil, $1000, InterruptThreadHandler, POINTER(pThread), 0, WinDriverGlobalDW);
phThread^ := HANDLE (pThread);
InterruptThreadEnable := True;
end;
procedure InterruptThreadDisable(hThread : HANDLE);
var
pThread : PINT_THREAD_DATA;
begin
if hThread <> 0
then
begin
pThread := PINT_THREAD_DATA (hThread);
WD_IntDisable(pThread^.hWD, pThread^.pInt^);
WaitForSingleObject(pThread^.hThread, INFINITE);
CloseHandle(pThread^.hThread);
Freemem(pThread);
end;
end;
end.